From dd29b0ab66d63b3b8e890c8de8f8e5c3fb44217a Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Sun, 20 Jul 2025 21:17:05 -0700 Subject: [PATCH] Fix Eshell call to 'string-suffix-p' when checking for trailing newline * lisp/eshell/esh-io.el (eshell--output-maybe-n): Fix call. * test/lisp/eshell/esh-io-tests.el (esh-io-test/output-newline/add-newline) (esh-io-test/output-newline/no-newline) (esh-io-test/output-newline/no-extra-newline): New tests (bug#79063). --- lisp/eshell/esh-io.el | 2 +- test/lisp/eshell/esh-io-tests.el | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lisp/eshell/esh-io.el b/lisp/eshell/esh-io.el index ff275560a04..1b474d988a7 100644 --- a/lisp/eshell/esh-io.el +++ b/lisp/eshell/esh-io.el @@ -569,7 +569,7 @@ ends in a newline." (eshell-output-object object handle) (when (and eshell-ensure-newline-p (not (and (stringp object) - (string-suffix-p object "\n")))) + (string-suffix-p "\n" object)))) (eshell-maybe-output-newline handle))) (defsubst eshell-print-maybe-n (object) diff --git a/test/lisp/eshell/esh-io-tests.el b/test/lisp/eshell/esh-io-tests.el index 0b25ad812fa..e6bc5c9809c 100644 --- a/test/lisp/eshell/esh-io-tests.el +++ b/test/lisp/eshell/esh-io-tests.el @@ -41,6 +41,28 @@ ;;; Tests: + +;; Newlines + +(ert-deftest esh-io-test/output-newline/add-newline () + "Ensure we add a newline when writing a string to stdout." + (with-temp-eshell + (eshell-match-command-output "(concat \"hello\")" "\\`hello\n\\'"))) + +(ert-deftest esh-io-test/output-newline/no-newline () + "Ensure we don't add a newline when writing a string to a buffer." + (eshell-with-temp-buffer bufname "" + (with-temp-eshell + (eshell-match-command-output + (format "(concat \"hello\") > #<%s>" bufname) + "\\`\\'")) + (should (equal (buffer-string) "hello")))) + +(ert-deftest esh-io-test/output-newline/no-extra-newline () + "Ensure we don't add an extra newline when writing to stdout." + (with-temp-eshell + (eshell-match-command-output "(concat \"hello\n\")" "\\`hello\n\\'"))) + ;; Basic redirection -- 2.30.2